package com.yeheng;

import java.util.HashMap;
import java.util.Map;

/**
 * @Classname SUMINDEX
 * @Description :
 * @Date 2021/3/9 20:21
 * @Created by Yeheng
 */

public class SUMINDEX {
    public static void main(String[] args) {
        int[] arr = {2,7,2,7};
        int target = 9;
        getIndex(arr,9);
    }

    public static void getIndex(int[] arr ,int target){
        int[] arr2 = arr;
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0;i < arr.length; i++){
            int x = target - arr[i];
            if (map.containsKey(x)){
                System.out.println("["+i+","+map.get(x)+"]");
            }
            map.put(arr[i],i);
        }
    }
}
